package javase.collections;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.TreeMap;
import java.util.TreeSet;

public class CollectionsNullElement {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ArrayList<Integer> arrayList = new ArrayList<Integer>();
		insertNull(arrayList);
		
		LinkedList<Integer> linkedList = new LinkedList<Integer>();
		insertNull(linkedList);
		
		HashSet<Integer> hashSet = new HashSet<Integer>();
		insertNull(hashSet);
		
		TreeSet<Integer> treeSet = new TreeSet<Integer>();
		insertNull(treeSet);
		
		LinkedHashSet<Integer> linkedHashSet = new LinkedHashSet<Integer>();
		insertNull(linkedHashSet);
		
//		HashMap<Integer, Integer> hashMap = new HashMap<Integer, Integer>();
//		insertNull(hashMap);
//		
//		LinkedHashMap<Integer, Integer> linkedHashMap = new LinkedHashMap<Integer, Integer>();
//		TreeMap<Integer, Integer> treeMap = new TreeMap<Integer, Integer>();

	}

	private static void insertNull(Collection<?> collection) {
		try {
			collection.add(null);
			System.out.println("Inserted null for " + collection.getClass().getSimpleName());
		} catch (Exception e) {
			System.out.println("Can't insert null for " + collection.getClass().getSimpleName());
		}
	}
}
